const loadGruntTasks = require("load-grunt-tasks");
const sass = require('sass');

// 实现这个项目的构建任务
module.exports = grunt => {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: {
            temp: 'dist/**'
        },
        sass: {
            options: {
                sourceMap: true,
                implementation: sass
            },
            main: {
                files: {
                    'dist/css/main.css': 'src/assets/styles/*.scss'
                }
            }
        },
        babel: {
            options: {
                sourceMap: true,
                presets: ['@babel/preset-env']
            },
            main: {
                files: {
                    'dist/js/app.js': 'src/assets/scripts/*.js'
                }
            }
        },
        watch: {
            js: {
                files: ['src/assets/scripts/*.js'],
                tasks: ['babel']
            },
            css: {
                files: ['src/assets/styles/*.scss'],
                tasks: ['sass']
            }
        },
    });

    loadGruntTasks(grunt);
    grunt.registerTask('default', ['sass', 'babel', 'watch'])
}